package com.xxx.modules.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxx.modules.mapper.LogMapper;
import com.xxx.modules.entity.Log;
import com.xxx.modules.service.LogService;
import com.xxx.modules.mapper.UserMapper;
import com.xxx.modules.utils.Result;
import com.xxx.modules.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import com.xxx.modules.utils.TimeUtil;
/**
 * 维修记录
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2024-03-30
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements LogService {

    @Autowired
    private LogMapper logMapper;



    /**
     *  获取所有维修记录接口实现类
     * @param pageNum
     * @param pageSize
     * @param log
     * @return
     */
    @Override
    public Result selectLogList(Log log, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Log> data = logMapper.selectListInfo(log);
       return ResultUtil.success(1,"成功",new PageInfo<>(data));
    }


    /**
     * 获取单个维修记录接口实现类
     * @param id
     * @return
     */
    @Override
    public Result selectLogInfo(Integer id) {
        Log log = logMapper.selectById(id);
        return ResultUtil.success(1,"成功",log);
    }

    /**
     * 保存维修记录接口实现类
     * @param log
     * @return
     */
    @Override
    public Result saveLogInfo(Log log) {
        log.setCreateTime(TimeUtil.getCurrentTime());
        log.setUpdateTime(TimeUtil.getCurrentTime());
        logMapper.insert(log);
        return ResultUtil.success(1,"成功",null);
}

    /**
     * 更新维修记录接口实现类
     * @param log
     * @return
     */
    @Override
    public Result updateLogInfo(Log log) {
        log.setUpdateTime(TimeUtil.getCurrentTime());
        logMapper.updateById(log);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id删除维修记录删除接口实现类
     * @param id
     * @return
     */
    @Override
    public Result delLogInfo(Integer id) {
        logMapper.deleteById(id);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id集合批量删除维修记录接口实现类
     * @param idList
     * @return
     */
    @Override
    public Result delBatchLogInfo(String idList) {
        List<String> list = Arrays.asList(idList.split(","));
        logMapper.deleteBatchIds(list);
        return ResultUtil.success(1,"成功",null);
    }



}